home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / layout / nsLayoutUtils.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  10KB  |  262 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Boris Zbarsky <bzbarsky@mit.edu>.
  19.  * Portions created by the Initial Developer are Copyright (C) 2002
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #ifndef nsLayoutUtils_h__
  39. #define nsLayoutUtils_h__
  40.  
  41. class nsIFrame;
  42. class nsPresContext;
  43. class nsIContent;
  44. class nsIAtom;
  45. class nsIScrollableView;
  46. class nsIScrollableFrame;
  47. class nsIDOMEvent;
  48.  
  49. #include "prtypes.h"
  50. #include "nsStyleContext.h"
  51. #include "nsAutoPtr.h"
  52. #include "nsStyleSet.h"
  53. #include "nsIView.h"
  54.  
  55. /**
  56.  * nsLayoutUtils is a namespace class used for various helper
  57.  * functions that are useful in multiple places in layout.  The goal
  58.  * is not to define multiple copies of the same static helper.
  59.  */
  60. class nsLayoutUtils
  61. {
  62. public:
  63.   /**
  64.    * GetBeforeFrame returns the :before frame of the given frame, if
  65.    * one exists.  This is typically O(1).  The frame passed in must be
  66.    * the first-in-flow.   
  67.    *
  68.    * @param aFrame the frame whose :before is wanted
  69.    * @return the :before frame or nsnull if there isn't one
  70.    */
  71.   static nsIFrame* GetBeforeFrame(nsIFrame* aFrame);
  72.  
  73.   /**
  74.    * GetAfterFrame returns the :after frame of the given frame, if one
  75.    * exists.  This will walk the in-flow chain to the last-in-flow if
  76.    * needed.  This function is typically O(N) in the number of child
  77.    * frames, following in-flows, etc.
  78.    *
  79.    * @param aFrame the frame whose :after is wanted
  80.    * @return the :after frame or nsnull if there isn't one
  81.    */
  82.   static nsIFrame* GetAfterFrame(nsIFrame* aFrame);
  83.  
  84.   /** 
  85.    * Given a frame, search up the frame tree until we find an
  86.    * ancestor "Page" frame, if any.
  87.    *
  88.    * @param the frame to start at
  89.    * @return a frame of type nsLayoutAtoms::pageFrame or nsnull if no
  90.    *         such ancestor exists
  91.    */
  92.   static nsIFrame* GetPageFrame(nsIFrame* aFrame);
  93.  
  94.   /**
  95.    * IsGeneratedContentFor returns PR_TRUE if aFrame is generated
  96.    * content of type aPseudoElement for aContent
  97.    *
  98.    * @param aContent the content node we're looking at.  If this is
  99.    *        null, then we just assume that aFrame has the right content
  100.    *        pointer.
  101.    * @param aFrame the frame we're looking at
  102.    * @param aPseudoElement the pseudo type we're interested in
  103.    * @return whether aFrame is the generated aPseudoElement frame for aContent
  104.    */
  105.   static PRBool IsGeneratedContentFor(nsIContent* aContent, nsIFrame* aFrame,
  106.                                       nsIAtom* aPseudoElement);
  107.  
  108.   /**
  109.    * CompareTreePosition determines whether aContent1 comes before or
  110.    * after aContent2 in a preorder traversal of the content tree.
  111.    * 
  112.    * @param aCommonAncestor either null, or a common ancestor of
  113.    *                        aContent1 and aContent2.  Actually this is
  114.    *                        only a hint; if it's not an ancestor of
  115.    *                        aContent1 or aContent2, this function will
  116.    *                        still work, but it will be slower than
  117.    *                        normal.
  118.    * @return < 0 if aContent1 is before aContent2
  119.    *         > 0 if aContent1 is after aContent2,
  120.    *         0 otherwise (meaning they're the same, or they're in
  121.    *           different documents)
  122.    */
  123.   static PRInt32 CompareTreePosition(nsIContent* aContent1,
  124.                                      nsIContent* aContent2,
  125.                                      nsIContent* aCommonAncestor = nsnull)
  126.   {
  127.     return DoCompareTreePosition(aContent1, aContent2, -1, 1, aCommonAncestor);
  128.   }
  129.  
  130.   /*
  131.    * More generic version of |CompareTreePosition|.  |aIf1Ancestor|
  132.    * gives the value to return when 1 is an ancestor of 2, and likewise
  133.    * for |aIf2Ancestor|.  Passing (-1, 1) gives preorder traversal
  134.    * order, and (1, -1) gives postorder traversal order.
  135.    */
  136.   static PRInt32 DoCompareTreePosition(nsIContent* aContent1,
  137.                                        nsIContent* aContent2,
  138.                                        PRInt32 aIf1Ancestor,
  139.                                        PRInt32 aIf2Ancestor,
  140.                                        nsIContent* aCommonAncestor = nsnull);
  141.   
  142.   /**
  143.    * GetLastSibling simply finds the last sibling of aFrame, or returns nsnull if
  144.    * aFrame is null.
  145.    */
  146.   static nsIFrame* GetLastSibling(nsIFrame* aFrame);
  147.  
  148.   /**
  149.    * FindSiblingViewFor locates the child of aParentView that aFrame's
  150.    * view should be inserted 'above' (i.e., before in sibling view
  151.    * order).  This is the first child view of aParentView whose
  152.    * corresponding content is before aFrame's content (view siblings
  153.    * are in reverse content order).
  154.    */
  155.   static nsIView* FindSiblingViewFor(nsIView* aParentView, nsIFrame* aFrame);
  156.  
  157.   /**
  158.    * IsProperAncestorFrame checks whether aAncestorFrame is an ancestor
  159.    * of aFrame and not equal to aFrame.
  160.    * @param aCommonAncestor nsnull, or a common ancestor of aFrame and
  161.    * aAncestorFrame. If non-null, this can bound the search and speed up
  162.    * the function
  163.    */
  164.   static PRBool IsProperAncestorFrame(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
  165.                                       nsIFrame* aCommonAncestor = nsnull);
  166.  
  167.   /**
  168.     * GetFrameFor returns the root frame for a view
  169.     * @param aView is the view to return the root frame for
  170.     * @return the root frame for the view
  171.     */
  172.   static nsIFrame* GetFrameFor(nsIView *aView)
  173.   { return NS_STATIC_CAST(nsIFrame*, aView->GetClientData()); }
  174.   
  175.   /**
  176.     * GetScrollableFrameFor returns the scrollable frame for a scrollable view
  177.     * @param aScrollableView is the scrollable view to return the 
  178.     *        scrollable frame for.
  179.     * @return the scrollable frame for the scrollable view
  180.     */
  181.   static nsIScrollableFrame* GetScrollableFrameFor(nsIScrollableView *aScrollableView);
  182.  
  183.   /**
  184.     * GetScrollableFrameFor returns the scrollable frame for a scrolled frame
  185.     */
  186.   static nsIScrollableFrame* GetScrollableFrameFor(nsIFrame *aScrolledFrame);
  187.  
  188.   static nsPresContext::ScrollbarStyles
  189.     ScrollbarStylesOfView(nsIScrollableView *aScrollableView);
  190.  
  191.   /**
  192.    * GetNearestScrollingView locates the first ancestor of aView (or
  193.    * aView itself) that is scrollable.  It does *not* count an
  194.    * 'overflow' style of 'hidden' as scrollable, even though a scrolling
  195.    * view is present.  Thus, the direction of the scroll is needed as
  196.    * an argument.
  197.    *
  198.    * @param  aView the view we're looking at
  199.    * @param  aDirection Whether it's for horizontal or vertical scrolling.
  200.    * @return the nearest scrollable view or nsnull if not found
  201.    */
  202.   enum Direction { eHorizontal, eVertical, eEither };
  203.   static nsIScrollableView* GetNearestScrollingView(nsIView* aView,
  204.                                                     Direction aDirection);
  205.  
  206.   /**
  207.    * HasPseudoStyle returns PR_TRUE if aContent (whose primary style
  208.    * context is aStyleContext) has the aPseudoElement pseudo-style
  209.    * attached to it; returns PR_FALSE otherwise.
  210.    *
  211.    * @param aContent the content node we're looking at
  212.    * @param aStyleContext aContent's style context
  213.    * @param aPseudoElement the name of the pseudo style we care about
  214.    * @param aPresContext the presentation context
  215.    * @return whether aContent has aPseudoElement style attached to it
  216.    */
  217.   static PRBool HasPseudoStyle(nsIContent* aContent,
  218.                                nsStyleContext* aStyleContext,
  219.                                nsIAtom* aPseudoElement,
  220.                                nsPresContext* aPresContext)
  221.   {
  222.     NS_PRECONDITION(aPresContext, "Must have a prescontext");
  223.     NS_PRECONDITION(aPseudoElement, "Must have a pseudo name");
  224.  
  225.     nsRefPtr<nsStyleContext> pseudoContext;
  226.     if (aContent) {
  227.       pseudoContext = aPresContext->StyleSet()->
  228.         ProbePseudoStyleFor(aContent, aPseudoElement, aStyleContext);
  229.     }
  230.     return pseudoContext != nsnull;
  231.   }
  232.  
  233.   /**
  234.    * If this frame is a placeholder for a float, then return the float,
  235.    * otherwise return nsnull.
  236.    */
  237.   static nsIFrame* GetFloatFromPlaceholder(nsIFrame* aPossiblePlaceholder);
  238.  
  239.   // Combine aNewBreakType with aOrigBreakType, but limit the break types
  240.   // to NS_STYLE_CLEAR_LEFT, RIGHT, LEFT_AND_RIGHT.
  241.   static PRUint8 CombineBreakType(PRUint8 aOrigBreakType, PRUint8 aNewBreakType);
  242.  
  243.   /**
  244.    * @return PR_TRUE if aFrame is the CSS initial containing block for
  245.    * its pres-shell
  246.    */
  247.   static PRBool IsInitialContainingBlock(nsIFrame* aFrame);
  248.  
  249.   /**
  250.    * Get the coordinates of a given DOM mouse event, relative to a given
  251.    * frame. Works only for DOM events generated by nsGUIEvents.
  252.    * @param aDOMEvent the event
  253.    * @param aFrame the frame to make coordinates relative to
  254.    * @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
  255.    * for some reason the coordinates for the mouse are not known (e.g.,
  256.    * the event is not a GUI event).
  257.    */
  258.   static nsPoint GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent, nsIFrame* aFrame);
  259. };
  260.  
  261. #endif // nsLayoutUtils_h__
  262.